package handlers

import (
	"game-hub/models"
	"github.com/gin-gonic/gin"
)

func AppAdd(c *gin.Context) {
	name := c.PostForm("name")
	app := models.App{
		Name: name,
	}
	err := models.DB.Create(&app).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "发布失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "发布成功",
	})
	return
}

func StateAdd(c *gin.Context) {
	keji := c.PostForm("keji")
	xiuxian := c.PostForm("xiuxian")
	state := models.State{
		KeJi:    keji,
		XiuXian: xiuxian,
	}
	err := models.DB.Create(&state).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "发布失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "发布成功",
	})
	return
}
func APPList(c *gin.Context) {
	var app []models.App
	err := models.DB.Find(&app).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "查询失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查询成功",
	})
	return
}
